package ch.ethz.inf.shop.model;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;

import ch.ethz.inf.shop.Title;

public final class Product {
	@Override
	public String toString() {
		return "Product [productId=" + productId + ", name=" + name + ", price=" + price + ", weight=" + weight + ", countryOfOrigin=" + countryOfOrigin
				+ ", category=" + category + ", brand=" + brand + "]";
	}

	@Title(text = "Product ID", isVisible = false)
	private final int productId;
	@Title(text = "Product Name", isVisible = true)
	private final String name;
	@Title(text = "Product Price", isVisible = true)
	private final BigDecimal price;
	@Title(text = "Product Weight", isVisible = true)
	private final int weight; // in grams
	@Title(text = "Product Country of Origin", isVisible = true)
	private final String countryOfOrigin;
	@Title(text = "Product Category", isVisible = true)
	private final Category category;
	@Title(text = "Product Brand", isVisible = true)
	private final Brand brand;
	@Title(text = "Popularity", isVisible = true)
	private final int likeCount;

	public Product(int product_id, String name, BigDecimal price, int weight, String countryOfOrigin, Category category, Brand brand, int likeCount) {
		this.productId = product_id;
		this.name = name;
		this.price = price;
		this.weight = weight;
		this.countryOfOrigin = countryOfOrigin;
		this.category = category;
		this.brand = brand;
		this.likeCount = likeCount;
	}

	public Product(final ResultSet rs) throws SQLException {

		this.productId = rs.getInt("product_id");
		this.name = rs.getString("product_name");
		this.price = rs.getBigDecimal("price");
		this.weight = rs.getInt("weight");
		this.countryOfOrigin = rs.getString("country_of_origin");
		this.brand = new Brand(rs);
		this.category = new Category(rs);
		this.likeCount = rs.getInt("like_cnt");

	}

	public int getProductId() {
		return productId;
	}

	public String getName() {
		return name;
	}

	public BigDecimal getPrice() {
		return price;
	}

	public int getWeight() {
		return weight;
	}

	public String getCountryOfOrigin() {
		return countryOfOrigin;
	}

	public Category getCategory() {
		return category;
	}

	public Brand getBrand() {
		return brand;
	}

	public int getLikeCount() {
		return likeCount;
	}

}
